#!/usr/bin/perl
# Version 0.2.1

$testcase = "bad_lsa_age";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$verdict = 3;

# Open the dumpfile
$state = 0;
$success = 1;
open(DUMPFILE, $dumpfile) or $success = 0;

if ($success eq 1) {
	
	while(<DUMPFILE>) {
		if($_ =~ /0\.0\.0\.2 > (.*) OSPFv2-ls_upd (.*) age 3600 rtr 0\.0\.0\.1/) {
			$state = $state | 1;
		}
		if($_ =~ /0\.0\.0\.2 > (.*) OSPFv2-ls_ack (.*) age 4711/) {
			# lsa with invalid age was acknowledged
			$state = $state | 2;
		}
	}
	close(DUMPFILE);
	
	if($state eq 0) {
		# bad aged lsa is ignored
		$verdict = 1;
	} elsif( $state eq 3 ) {
		# bad aged lsa ich acknowledged and max-aged
		$verdict = 1;
	} else {
		$verdict = 2;
	}
}

if ($state & 2) {
	print("LSAs with invalid age are acknowledged. ");
} 
if ($state & 1) {
	print("LSAs with invalid age are max-aged. ");
}

if( $verdict eq 1 ) {
	print("Test PASSED.\n");
} elsif( $verdict eq 2 ) {
	print("Test FAILED.\n");
} else {
	print("Cannot evaluate results. Test INCONCLUSIVE.\n");
}






#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");